﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TiposComuns.Objectos;

namespace Servidor.Objectos
{
    /// <summary>
    /// Updating user's profile
    /// </summary>
    [Serializable]
    public class UpdateProfileAction : Action
    {
        #region Attributes
        private Profile profile;            //Updated profile
        private Profile antigo;
        #endregion

        #region Constructors
        public Profile Profile
        {
            get { return profile.Clone(); }
            set { profile = value.Clone(); }
        }


        public Profile Antigo
        {
            get { return antigo; }
            set { antigo = value; }
        }


        public UpdateProfileAction() { }

        public UpdateProfileAction(IDMsg id, Profile profile, Profile antigo) : base(id)
        {
            this.profile = profile.Clone();
            this.Id = id;
            this.antigo = antigo;
        }
        #endregion

        #region Methods
        public override void Execute(User user)
        {
            user.UpdateProfile(profile);
        }

        public override void RollBack(User user)
        {
            user.Perfil = this.antigo;
        }

        #endregion
    }
}
